module.exports = function (app, mongoose, jwt) {
  // 设置token秘钥
  const tokenKey = 'myToken';
  // 登录页面的接口
  app.post("/login", function (req, res) {
    console.log(req.body.username)
    // console.log(req.headers.authentication)
    // 获取数据库Users模块
    var Users = mongoose.model("Users");
    // /** 查询所有数据 **/
    Users.findOne({
        username: req.body.username
      },
      function (err, docs) {
        if (err) {
          console.log("err:", err);
        } else {
          if (docs) {
            if (
              docs.username == req.body.username &&
              docs.password == req.body.password
            ) {
              res.json({
                status: 0,
                msg: "登录成功！",
                username: docs.username,
                usericon: docs.usericon,
                token: jwt.sign({
                  name: req.query.username,
                  role: docs.role
                }, tokenKey, {
                  expiresIn: 60 * 60 * 24 * 7
                }),
                role: docs.role
              });
            } else {
              res.json({
                status: 1,
                msg: "用户名密码错误！"
              });
            }
          } else {
            res.json({
              status: 1,
              msg: "用户名密码错误！"
            });
          }
        }
      }
    );
  });
}
